<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"/>
    <title>首页 - 光年(Light Year Admin)后台管理系统模板</title>
    <link rel="icon" href="favicon.ico" type="image/ico">
    <meta name="keywords" content="LightYear,光年,后台模板,后台管理系统,光年HTML模板">
    <meta name="description" content="LightYear是一个基于Bootstrap v3.3.7的后台管理系统的HTML模板。">
    <meta name="author" content="yinqi">
    <link th:href="@{/admin/css/bootstrap.min.css}" type="text/css" rel="stylesheet">
    <link th:href="@{/admin/css/materialdesignicons.min.css}" type="text/css" rel="stylesheet">
    <link th:href="@{/admin/css/style.min.css}" type="text/css" rel="stylesheet">
</head>

<body>
<div class="lyear-layout-web">
    <div class="lyear-layout-container">
        <!--左侧导航-->
        <aside class="lyear-layout-sidebar">

            <!-- logo -->
            <div id="logo" class="sidebar-header">
                <a th:href="@{/manage/index}"><img src="/admin/images/logo-sidebar.png" title="LightYear" alt="LightYear"/></a>
            </div>
            <div class="lyear-layout-sidebar-scroll">

                <nav class="sidebar-main">
                    <ul class="nav nav-drawer">
                        <li class="nav-item active">
                            <a th:href="@{/manage/index}"><i class="mdi mdi-home"></i>后台首页</a>
                        </li>
                        <li class="nav-item ">
                            <a th:href="@{/manage/toNovel}"><i class="mdi mdi-book-open"></i> 书籍管理</a>
                        </li>
                        <li class="nav-item ">
                            <a th:href="@{/manage/recharge}"><i class="mdi mdi-diamond"></i> 充值管理</a>
                        </li>
                        <li class="nav-item ">
                            <a th:href="@{/manage/toComment}"><i class="mdi mdi-record"></i> 评论管理</a>
                        </li>
                        <li class="nav-item ">
                            <a th:href="@{/manage/toPassApply}"><i class="mdi mdi-compass"></i> 审批作家</a>
                        </li>
                        <li class="nav-item ">
                            <a th:href="@{/manage/system/param}"><i class="mdi mdi-brightness-5"></i> 系统设置</a>
                        </li>
                        <li class="nav-item ">
                            <a th:href="@{/manage/system/log}"><i class="mdi mdi-grease-pencil"></i> 系统日志</a>
                        </li>
                    </ul>
                </nav>
            </div>

        </aside>
        <!--End 左侧导航-->

        <!--头部信息-->
        <header class="lyear-layout-header">

            <nav class="navbar navbar-default">
                <div class="topbar">

                    <div class="topbar-left">
                        <div class="lyear-aside-toggler">
                            <span class="lyear-toggler-bar"></span>
                            <span class="lyear-toggler-bar"></span>
                            <span class="lyear-toggler-bar"></span>
                        </div>
                        <span class="navbar-page-title"> 个人信息 </span>
                    </div>

                    <ul class="topbar-right">
                        <li class="dropdown dropdown-profile">
                            <a href="javascript:void(0)" data-toggle="dropdown">
                                <img class="img-avatar img-avatar-48 m-r-10" th:src="${session.loginUser.imgSrc}"
                                     alt="笔下光年"/>
                                <span th:text="${session.loginUser.userName}"> <span class="caret"></span></span>
                            </a>
                            <ul class="dropdown-menu dropdown-menu-right">
                                <li><a th:href="@{/manage/toInfo}"><i class="mdi mdi-account"></i> 个人信息</a></li>
                                <li><a th:href="@{/manage/toChangePwd}"><i class="mdi mdi-lock-outline"></i> 修改密码</a>
                                </li>
                                <li><a th:href="@{/index}"><i class="mdi mdi-lock-outline"></i> 回到门户网站</a>
                                </li>
                                <li class="divider"></li>
                                <li><a th:href="@{/manage/logout}"><i class="mdi mdi-logout-variant"></i> 退出登录</a>
                                </li>
                            </ul>
                        </li>
                    </ul>

                </div>
            </nav>

        </header>
        <!--页面主要内容-->
        <main class="lyear-layout-content">

            <div class="container-fluid">

                <div class="row">
                    <div class="col-lg-12">
                        <div class="card">
                            <div class="card-body">

                                <div class="edit-avatar">
                                    <img th:src="${session.loginUser.imgSrc}" alt="..." class="img-avatar">
                                    <div class="avatar-divider"></div>
                                </div>
                                <hr>
                                <form id="change-manage-info">
                                    <div class="form-group">
                                        <label for="userEmail">用户邮箱</label>
                                        <input th:value="${session.loginUser.userEmail}" type="text"
                                               class="form-control" name="userEmail" id="userEmail"
                                               disabled="disabled"/>
                                    </div>
                                    <div class="form-group">
                                        <label for="userName">昵称</label>
                                        <input th:value="${session.loginUser.userName}" type="text" class="form-control"
                                               name="userName" id="userName" placeholder="输入您的昵称" value="笔下光年">
                                    </div>
                                    <div class="form-group">
                                        <label for="telephone">电话号码</label>
                                        <input th:value="${session.loginUser.telephone}" type="tel" class="form-control"
                                               name="telephone" id="telephone" aria-describedby="emailHelp"
                                               placeholder="请输入正确的电话">
                                        <small id="emailHelp" class="form-text text-muted">请保证您填写的电话号码正确的。</small>
                                    </div>
                                    <div class="form-group">
                                        <label for="introduction">简介</label>
                                        <textarea th:text="${session.loginUser.introduction}" class="form-control"
                                                  name="introduction" id="introduction" rows="3"></textarea>
                                    </div>
                                    <button type="submit" class="btn btn-primary">保存修改</button>
                                </form>

                            </div>
                        </div>
                    </div>

                </div>

            </div>

        </main>
        <!--End 页面主要内容-->


    </div>
</div>

<script type="text/javascript" th:src="@{/admin/js/jquery.min.js}"></script>
<script type="text/javascript" th:src="@{/admin/js/bootstrap.min.js}"></script>
<script type="text/javascript">

    $(function () {
        //监听表单提交
        $("#change-manage-info").submit(function () {

            let result = confirm("您确定要修改信息吗？");
            if (result) {
                //获取数据
                let data = $("#change-manage-info").serialize();
                //发起请求修改数据
                $.ajax({
                    url: "/manage/change/info",
                    data: data,
                    method: "post",
                    success: function (result) {
                        if (result == true) {
                            alert("个人信息修改成功");
                            location.reload();
                        } else if (result == false) {
                            alert("个人信息修改失败！");
                        } else {
                            //触发异常，用户未登录
                            alert(result.message);
                            location.href = "/login";
                        }
                    },
                })
            }
            return false;
        });
    })

</script>
</body>
</html>
